#include <iostream>
#include <pthread.h>
#include <signal.h>
#include <unistd.h>
#include "errno.h"
#include <stdio.h>

void mycleanfunc(void *arg)
{
    printf("my clean func:%d\n", *((int *)arg));
}

void *thfrunc1(void *arg)
{
    int m = 1;
    printf("thfunc1 comes \n");
    pthread_cleanup_push(mycleanfunc, &m);
    return (void *)0;
    pthread_cleanup_pop(0);
}

void *thfrunc2(void *arg)
{
    int m = 2;
    printf("thfunc2 comes \n");
    pthread_cleanup_push(mycleanfunc, &m);
    return (void *)0;
    pthread_cleanup_pop(0);
}

int main()
{
    pthread_t pid1, pid2;
    int res;
    res=pthread_create(&pid1,NULL,thfrunc1,NULL);
    pthread_join(pid1,NULL);
    pthread_create(&pid2,NULL,thfrunc2,NULL);
    pthread_join(pid2,NULL);
    printf("main over\n");
}